package com.zhs.smartmall.order.service.impl;


import com.zhs.smartmall.order.model.MqMessage;
import com.zhs.smartmall.order.dao.MqMessageDao;
import com.zhs.smartmall.order.service.IMqMessageService;
import com.zhs.smartmall.order.dto.MqMessageDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-12
 */
@Service
@Slf4j
public class MqMessageServiceImpl extends ServiceImpl< MqMessageDao, MqMessage> implements IMqMessageService {

    @Resource
    private MqMessageDao mqMessageDao;

    @Override
    @Transactional
    public R addOrUpdate(MqMessageDto mqMessageDto) {
        if (BeanUtil.isEmpty(mqMessageDto)) throw new ServiceException("数据不能为空");
        MqMessage mqMessage = new MqMessage();
        BeanUtil.copyProperties(mqMessageDto,mqMessage);
        if (mqMessageDto.getId() == null){
            mqMessageDao.insert(mqMessage);
            return R.ok("数据插入成功");
        }else {
            mqMessageDao.updateById(mqMessage);
            return R.ok("数据更新成功");
        }
    }
}